<?php

namespace app\common\command;


use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\common\model\user\User;


class UpdateUser extends Command
{
    protected function configure()
    {
        $this->setName('update_user')
            ->setDescription('更新用资料');
    }

    protected function execute(Input $input, Output $output)
    {
        try {

            $user = User::where('id','>',0)
                ->select()->toArray();

            $leaderAccount = '';
            foreach ($user as $value) {
                if($value['role_id']>3){
                    $leaderAccount = User::where('id',$value['pid'])->value('account');
                }else{
                    $leaderAccount = '';
                }
                User::where('id',$value['id'])->update(['leader_account'=>$leaderAccount]);
            }


            return true;
        } catch (\Exception $e) {
            trace('失败原因:' . $e->getMessage(), 'error');
            return false;
        }
    }




}